
<!DOCTYPE html>
<head>
	<meta charset="UTF-8">
	<METAHTTP-EQUIV="Pragma"CONTENT="no-cache">
	<METAHTTP-EQUIV="Cache-Control"CONTENT="no-cache">
	<METAHTTP-EQUIV="Expires"CONTENT="0">
	<title>登录</title>
	<meta name="keywords" content="" />
	<meta name="description" content="" />
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	
	<link href="css/font-awesome.min.css" rel="stylesheet" type="text/css">
	<link href="css/bootstrap.css" rel="stylesheet" type="text/css">
	<link href="css/bootstrap-theme.min.css" rel="stylesheet" type="text/css">
	<link href="css/templatemo_style.css" rel="stylesheet" type="text/css">	
	<script src="js/jquery.js"></script>
<script src="js/angular.js"></script>
<script type="text/javascript" src="js/bootstrap.js"></script>
</head>
<body class="templatemo-bg-gray">

	<div class="container"  ng-app="myApp" ng-controller="siteCtrl"  ng-keyup="loginKeyUp($event)">
		<div class="col-md-12">
			<h1 class="margin-bottom-15">公众号助手</h1>
			<form class="form-horizontal templatemo-container templatemo-login-form-1 margin-bottom-30" role="form" action="#" method="post">				
		        <div class="form-group">
		          <div class="col-xs-12">		            
		            <div class="control-wrapper">
		            	<label for="username">用户名</label>
		            	<input type="text" class="form-control" id="username" ng-model="username" placeholder="用户名">
		            </div>		            	            
		          </div>              
		        </div>
		        <div class="form-group">
		          <div class="col-md-12">
		          	<div class="control-wrapper">
		            	<label for="username">密码</label>
		            	<input type="password" class="form-control" id="password" ng-model="password" placeholder="密码">
		            </div>
		          </div>
		        </div>
		        <div class="form-group">
		          <div class="col-md-12">
	             	<div class="checkbox control-wrapper">
	                	<label>
	                  		<input type="checkbox" ng-checked="remember_check" ng-model="remember"/> 记住用户名
                		</label>
	              	</div>
		          </div>
		        </div>
		        <div class="form-group" style="text-align: right;">
		         <input type="button" class="btn btn-primary" ng-click="submit()" 
							value="登录"></div>
		      </form>
		</div>
	</div>
	<script type="text/javascript">
	 var app = angular.module('myApp', []);
    
	app.controller('siteCtrl', function($scope, $http) {
		$scope.submit=function(){
			var data={
					username:$scope.username,
					password:$scope.password
			};
			$http({url:'/loginService',method:'post',data:JSON.stringify(data),headers:{'Content-Type': 'application/json'}}).then(function successCallback(response) {
				console.log(response)
				if(response.data.code==200){
					if($scope.remember){
	            		localStorage.setItem("username",$scope.username);
	            		localStorage.setItem("remember",$scope.remember);
	            	}else{
	            		localStorage.removeItem("username");
	            	}
					location.href="index.html";
				}else{
					alert(response.data.message);
				}
		    }, function errorCallback(response) {
		            // 请求失败执行代码
		    	console.log(response)
		    });
		}
		
		$scope.loginKeyUp=function(e){
			var keycode = window.event?e.keyCode:e.which;
            if(keycode==13){
    			$scope.submit();
            }
		}
		var username=localStorage.getItem("username");
		if(username){
			$scope.username=username;
		}
		var remember=localStorage.getItem("remember");
		if(remember){
			$scope.remember_check=remember;
		}
	}); 
	
	</script>
</body>
</html>